{extend name="web/public/base" /}
{block name="header"}
{/block}
{block name="main"}
<section class="scrollable padder">
    <ul class="breadcrumb no-border no-radius b-b b-light pull-in">
        <li><a><i class="fa fa-home"></i> 首页</a></li>
        <li class="active">管理员</li>
        <li class="active">{$title}</li>
    </ul>
    <div class="row">
        <div class="col-sm-12">
            <section class="panel panel-default">
                <header class="panel-heading font-bold">{$title}</header>
                <div class="panel-body">
                    <form id="ajaxform" action="{:url('')}" role="form" method="post" onsubmit="return false;">
                        <div class="row col-md-10">
                            <div class="row col-lg-12">
                                <div class="form-group col-sm-6">
                                    <label>管理员账号</label>
                                    {eq name="manager.mid" value="1"}
                                    <span class="form-control">{$manager['mname']}</span>
                                    {else/}
                                    <input type="text" name="mname" class="form-control" placeholder="管理员账号"
                                           value="{$manager['mname']}">
                                    {/eq}
                                </div>
                                <div class="form-group col-sm-6">
                                    <label>邮箱</label>
                                    <input type="text" id="email" name="email" class="form-control" placeholder="邮箱"
                                           value="{$manager['email']}">
                                </div>

                            </div>
                            <div class="row col-lg-12">
                                <div class="form-group col-sm-6">
                                    <label>密码</label>
                                    <input type="password" id="password" name="password" class="form-control"
                                           placeholder="密码" value="">
                                </div>
                                <div class="form-group col-sm-6">
                                    <label>确认密码</label>
                                    <input type="password" id="repassword" name="repassword" class="form-control"
                                           placeholder="确认密码">
                                </div>
                            </div>
                            <footer class="panel-footer text-right bg-light lter col-sm-12">
                                <input type="hidden" name="id" value="{$id}">
                                <input type="hidden" name="code" value="">
                                <button type="submit" class="btn btn-success btn-s-xs">提 交</button>
                            </footer>
                        </div>
                    </form>
                </div>
            </section>
        </div>
    </div>
</section>
{/block}
{block name="script"}
<script>
    $(function () {
        layer.config({extend: 'extend/layer.ext.js'})
        $.validator.setDefaults({
            submitHandler: function () {
                var email = "{$email}";
                if (!email) {
                    layer.msg("邮箱不存在")
                    return false;
                }
                $.post("/index/Home/getEmailCode", {email: email}, function (data) {
                    var code = data.substr(data.length - 1, 1)
                    if (code == 0) {
                        layer.msg('邮箱验证码发送失败！');
                        return false;
                    }
                    layer.prompt({
                        title: '请输入您的邮箱收到的验证码',
                    }, function (value, index, elem) {

                        var reg = new RegExp("^[0-9]{6}$");
                        if (!reg.test(value)) {
                            layer.msg("请输入正确验证码")
                            return false;
                        }
                        $('input[name=code]').val(value)
                        ajaxSubmit();
                    });
                }, 'html')
            },
            highlight: function (element, errorClass) {
                $(element).css('border', '2px solid red');
            },
            unhighlight: function (element, errorClass) {
                $(element).css('border', '1px solid green');
            }
        });

        $.validator.addMethod("checkPwd", function (value, element, params) {
            var checkPwd = /^\w{6,16}$/g;
            return this.optional(element) || (checkPwd.test(value));
        }, "*只允许6-16位英文字母、数字或者下画线！");

        $('#ajaxform').validate({
            rules: {
                email: {
                    required: true,
                    email: true
                },
                password: {
                    required: true,
                    checkPwd: true
                },
                repassword: {
                    equalTo: "#password"
                }
            },
            messages: {
                email: "请输入一个正确的邮箱",
                password: "请输入一个正确的密码",
                repassword: "确认密码和密码必须一致"
            }
        });
    })
</script>
{/block}
